package br.com.academia.DAO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import br.com.academia.beans.Aluno;
import br.com.academia.beans.NotificacaoAluno;

public class NotificacoesAlunoDAO {
	private Connection connection;
	
	public NotificacoesAlunoDAO(Connection connection) {
		this.connection = connection;
	}
	
	public List<NotificacaoAluno> consultaNotificacoes()  {
		List<NotificacaoAluno> retorno = new ArrayList<NotificacaoAluno>();
		String query = "Select  Notificacoes_Aluno.textoNotificacao, Alunos.nome, Alunos.sobreNome from Notificacoes_Aluno " +
				" Inner Join Alunos on Notificacoes_Aluno.Alunos_idAluno = Alunos.idAluno " +
				" Order By idNotificacoes_Aluno Desc";
		 try {
			 PreparedStatement stm = connection.prepareStatement(query);
			 ResultSet rs = stm.executeQuery();
			 while(rs.next()) {
				 NotificacaoAluno na = new NotificacaoAluno();
				 na.setTextoNotificacao(rs.getString("textoNotificacao"));
				 na.setAluno(new Aluno());
				 na.getAluno().setNome(rs.getString("nome"));
				 na.getAluno().setSobreNome(rs.getString("sobreNome"));
				 retorno.add(na);
			 }
		 } catch(SQLException e) {
			 e.printStackTrace();
		 }
		return retorno;
	}

}
